package com.csdj.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.csdj.server.pojo.Employee;
import com.csdj.server.pojo.RespBean;
import com.csdj.server.pojo.RespPageBean;
import com.csdj.server.pojo.Salary;
import com.csdj.server.service.IEmployeeService;
import com.csdj.server.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zyq
 * @Date 2023/2/7 10:29
 * @ClassName: SalarySobCfgController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/salary/sobcfg")
@Api(tags = "员工账套管理")
public class SalarySobCfgController {

    @Autowired
    private IEmployeeService employeeService;

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "员工账套管理分页查询")
    @GetMapping("/")
    public RespPageBean getEmployeeWithSalary(@RequestParam(defaultValue = "1") Integer current,
                                              @RequestParam(defaultValue = "10") Integer size){

        return employeeService.getEmployeeWithSalary(current,size);

    }

    @ApiOperation(value = "获取所有的工资账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries(){

        return salaryService.list();
    }

    @ApiOperation(value = "更新员工账套")
    @PutMapping("/")
    public RespBean updateSalary(Integer eid,Integer sid){

        boolean result = employeeService.update(new UpdateWrapper<Employee>().set("salaryId", sid)
                .eq("id", eid));
        if(result){
            return RespBean.success("更新成功!");
        }
        return RespBean.error("更新失败!");
    }


}
